<%@page pageEncoding = "utf-8" contentType = "text/html;charset=utf-8"%>

<%@taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt"%>

<script type="text/javascript">
window.onload = function () {
  dates  = new Epoch('epoch_popup','popup',document.getElementById('enddate'));
};
</script>


<c:if test="${action == 'requestCommitForm'}">
  <h2>Принять / Отменить заявку</h2>
</c:if>

<c:if test="${action == 'requestEditForm'}">
  <h2>Редактировать заявку</h2>
</c:if>


<div class = "messages"><jsp:include page = "/messages.jsp"/></div>

<form action = "${sessionScope.alias}" method = "post" name = "requestForm">
   
   <table class = "form">                                 
     <tr>
         <td class = "label">
           Название<span class="star">*</span>
         </td>
         <td>
            <input name="name" type="text" value='<c:out value = "${requestBean.name}"/>'>
            <span class="error"><c:out value="${error.name}"/></span>
         </td>
      </tr>   
   
      <tr>
         <td class = "label">
           Текст заявки<br>
           <span class="small">(Заполняется клиентом)</span>
         </td>
         <td>
            <textarea name = "text" rows="10" cols="50"><c:out value = "${requestBean.clientText}"/></textarea>
         </td>
      </tr>     
      
      <tr>
         <td class = "label">
           Текст заявки<br>
           <span class="small">(Заполняется диспетчером)</span><span class="star">*</span>
         </td>
         <td>
            <textarea name = "dispatcherText" rows="10" cols="50"><c:out value = "${requestBean.dispatcherText}"/></textarea>
            <span class="error"><c:out value="${error.dispatcherText}"/></span>
         </td>
      </tr>

      <tr>
         <td class = "label"><fmt:message key = "request.requestType"/></td>
         <td>
            <select name="requesttype_id">              
              <c:forEach var = "requestType" items = "${requestTypesList}">
                <option value="${requestType.id}" ${requestType.id == requestBean.requestTypeId ? "selected" : ""}>
                   <c:out value="${requestType.type}"/>
                </option>
              </c:forEach>
            </select>            
            <span class="error"><c:out value="${error.requestType}"/></span>
         </td>
      </tr>

      <tr>
         <td class = "label"><fmt:message key = "request.approxEndDate"/><span class="star">*</span></td>
         <td>
            <input class="date" id="enddate" type="text" name="approxEndDate" value='<fmt:formatDate value="${requestBean.approxEndDate}" pattern="dd.MM.yyyy"/>'/>
            <span class="error"><c:out value="${error.approxEndDate}"/></span>
         </td>
      </tr>

      <tr>
         <td class = "label"><fmt:message key = "request.priority"/><span class="star">*</span></td>
         <td>
            <ul class="simple"> 
            <c:forEach var = "priority" items = "${priorityList}">
               <li>
                  <input type="radio" name="priority" value="${priority.id}" ${priority.id == requestBean.priority ? "checked" : ""}/>
                  ${priority.value}
               </li>            
            </c:forEach>
            <span class="error"><c:out value="${error.priority}"/></span>
            </ul>
         </td>
      </tr>
      
      <tr>
         <td class = "label"><fmt:message key = "request.comment"/></td>
         <td>
            <textarea name = "comment" rows="10" cols="50"><c:out value = "${requestBean.comment}"/></textarea>
            <span class="error"><c:out value="${error.comment}"/></span>
         </td>
      </tr>
</table>
      
   <input name="request_id" type="hidden" value="${requestBean.id}">
   <input name="action" type="hidden" value="${action}">   

<p>Обязательные для заполнения поля отмечены <span class="star">*</span></p>

<!-- bottom links -->

<p>
    <c:if test="${action == 'requestCommitForm'}">
      <input name = "_action" type = "hidden" value="commitRequest">
      <input type="submit" value="Принять" onclick="return confirm('Вы действительно хотите принять заявку?')"> или      
      <a href='javascript:doAction("cancelRequest");' onclick="return confirm('Вы действительно хотите отменить заявку?')">Отменить</a>
    </c:if>

    <c:if test="${action == 'requestEditForm'}">
      <input name = "_action" type = "hidden" value="updateRequest">
      <input type="submit" value="Сохранить" onclick="return confirm('Вы действительно хотите сохранить изменения?')">
    </c:if>
</p>
  
</form>